<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8"/>
  <meta name="renderer" content="webkit"/>
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
  <meta http-equiv="Pragma" content="no-cache"/>
  <meta http-equiv="Cache-Control" content="no-cache,must-revalidate"/>
  <meta http-equiv="Expires" content="web,26 Feb 1997 08:21:57GMT"/>
  <meta http-equiv="Cache" content="no-cache"/>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
  <title>题库列表</title>
  <th:block th:include="common/pub_head :: default"></th:block>
  <th:block th:include="common/pub_head :: layui"></th:block>
  <style>
    .layui-table-view {
      margin-top: 0px;
    }
  </style>
</head>
<body>
<div class="layui-col-md-offset2 layui-col-md8">
  <div class="layui-card-header" style="margin-bottom: 5px">
    <h2>错题集列表</h2>
  </div>
  <form action="" class="layui-form" id="list_form">
    <div class="layui-form-item" style="text-align: center;">
      <div class="layui-inline">
        <label class="layui-form-label">创建时间:</label>
        <div class="layui-input-inline" style="margin-right: 0;">
          <input type="text" class="layui-input" id="beginTime" placeholder="yyyy-MM-dd HH:mm:ss">
        </div>
        <label class="layui-form-label" style="text-align: center;width: 20px;padding-left:0;padding-right: 0;">-</label>
        <div class="layui-input-inline">
          <input type="text" class="layui-input" id="endTime" placeholder="yyyy-MM-dd HH:mm:ss">
        </div>
        <button class="layui-btn pull-right" type="button" onclick="listError()">搜索</button>
        <button class="layui-btn pull-right" type="button" onclick="clearForm()" style="margin-left: 10px">清空</button>
      </div>
    </div>
  </form>
  <!-- 数据列表-->
  <table class="layui-table" lay-filter="demo" id="errorList" style="margin: 0; width: 100%;"></table>
</div>
<script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
    <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="batchDel">批量删除</button>
  </div>
</script>
<!--表格操作-->
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
  <a class="layui-btn layui-btn-xs" lay-event="check">回顾</a>
</script>
<script>
  /*<![CDATA[*/
  function batchDelError(selectId) {
    var URL = path + "/answer/batchDelAnswerCard";
    var formData = {
      selectId: selectId + ""
    };
    $.post(URL, formData, function (jsonData) {
      var flag = jsonData.flag;
      if (flag) {
        layer.alert("删除成功");
        listError();
      } else {
        layer.alert("删除失败，错误信息为: " + jsonData.errroMsg);
      }
    }, "json");
  }

  /*]]>*/
</script>
<script>
  /*<![CDATA[*/
  var table;
  $(function () {
    layui.use(['table', 'form', 'laydate'], function () {
      table = layui.table;
      var laydate = layui.laydate;
      laydate.render({
        elem: '#beginTime'
        , type: 'datetime'
      });
      laydate.render({
        elem: '#endTime'
        , type: 'datetime'
      });

      table.render({
        elem: '#errorList',
        id: 'errorList',
        toolbar: '#toolbarDemo',
        url: path + '/answer/listError',
        cols: [[
          {type: 'checkbox', field: "id"},
          {field: 'title', title: '题库标题', align: 'center', width: 300},
          {
            field: 'answerTime', title: '答题时间', align: 'center', width: 150, templet: function (d) {
              return d.answerTime + '分';
            }
          },
          {field: 'createTime', title: '创建时间', align: 'center', width: 200},
          {fixed: 'right', title: '操作', toolbar: '#barDemo'}
        ]],
        request: {
          pageName: 'pn',
          limitName: 'pageSize' //每页数据量的参数名，默认：limit
        },
        page: true
      });

      //头工具栏事件
      table.on('toolbar(demo)', function (obj) {
        var checkStatus = table.checkStatus(obj.config.id);
        switch (obj.event) {
          case 'batchDel':
            var data = checkStatus.data;
            var selectId = [];
            $.each(data, function (index, domEle) {
              selectId.push(domEle.id);
            });
            if (selectId.length == 0) {
              layer.alert("请先选择数据");

              return;
            }
            layer.confirm('真的删除数据么', function (index) {
              batchDelError(selectId);
            });

            break;
        }
      });

      table.on('tool(demo)', function (obj) {
        var data = obj.data;
        var selectId = [data.id];
        switch (obj.event) {
          case 'del' :
            layer.confirm('真的删除数据么', function (index) {
              batchDelError(selectId);
              layer.close(index);
            });
            break;
          case 'check' :
            location.href = path + '/answer/error/' + selectId;
            break;
        }
      });
    });
  });

  document.onkeydown = EnterLogin;

  function EnterLogin(event) {
    if (event.keyCode == 13) {
      listError();
    }
  }

  function clearForm() {
    $("#list_form")[0].reset();
  }


  var index = 0;

  function listError() {
    var beginTime = $("#beginTime").val();
    var endTime = $("#endTime").val();
    if (beginTime == '' || endTime == '') {
      layer.close(index);
      table.reload('errorList', {
        page: {
          curr: 1 //重新从第 1 页开始
        },
        where: {
          beginTime: $("#beginTime").val(),
          endTime: $("#endTime").val()
        }
      });
    }
    beginTime = new Date(beginTime);
    endTime = new Date(endTime);
    if (beginTime > endTime){
      layer.msg('开始时间不能大于结束时间!', {icon: 6});
    }
  }
  /*]]>*/
</script>
</body>
</html>
